(function () {
    function PropsAlertUI() {
        PropsAlertUI.super(this);
        this.isPopup = false;
        this.custom = true;

        this._props = [];
        this._player = {};

        this.bindEvent();
    }
    Laya.class(PropsAlertUI, "ui.Alert.Props", ui.Alert.PropsUI);
    var _proto = PropsAlertUI.prototype;
    
    _proto.bindEvent = function () {
        this.alertMask.on(Laya.Event.CLICK, this, function () {
            this.close();
        });

        this.propList.renderHandler = new Laya.Handler(this.propList, function (item, index) {
            if(!this.propsData || index >= this.propsData.length){return;}
            var prop = item.getChildByName("prop").getChildByName("item");
            var price = item.getChildByName("price");

            prop.skin = this.propsData[index].img;
            price.text = this.propsData[index].price;
        });

        this.propList.selectHandler = new Laya.Handler(this, function (index) {
            if(index < 0){return;}
            viewer.publish("io.emit", {
                cmd : "prop::use",
                params : {
                    token : token,
                    targetUserId : this._player.uid,
                    itemId : this._props[index].id
                }
            });

            this.close();
        });
        
        viewer.register("prop::list", this.updatePropsList.bind(this));
    }

    _proto.updatePropsList = function (res) {
        this._props = res.list;
        this.propList.propsData = this._props;
        this.propList.array = this._props;
    }
    _proto.display = function (player) {
        this.isPopup = true;
        this.width = Laya.stage.width;

        viewer.publish("io.emit", {
            cmd : "prop::list",
            params : {
                token : token
            }
        });
        
        this._player = player;

        this.propList.array = [];
        this.propList.selectedIndex = -1;

        this.alertContent.alpha = 0;
        this.alertContent.scale(0, 0);

        this.userName.text = (player.uname || player.uid);
        this.userRound.text = player.count;
        this.userAvatar.loadImage(player.avatar, 0, 0, 104, 104, Laya.Handler.create(this.userAvatar, function (avatar) {
            this.skin = avatar;
        }, [player.avatar]));

        Arena.Stage.addChild(this);
        Laya.Tween.to(this.alertContent, {scaleX : 1, scaleY : 1, alpha : 1}, 500, Laya.Ease.bounceOut);
    }
    _proto.close = function () {
        this.isPopup = false;

        this._player = {};
        this._props = [];
        this.removeSelf();
    }
})();